//
//  GlobalUtil.h
//  SZYH2
//
//  Created by ZZB on 13-7-16.
//  Copyright (c) 2013年 JMU. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>


#pragma mark - MACRO

/**
 * UIViewController
 */
#define VC_ON_BACK_CLICK()          \
if (self.navigationController) {    \
if (self.navigationController.viewControllers && self.navigationController.viewControllers.count <= 1) {    \
[self.navigationController dismissViewControllerAnimated:YES completion:^{}];   \
} else {    \
[self.navigationController popViewControllerAnimated:YES];  \
}   \
} else {    \
[self dismissViewControllerAnimated:YES completion:^{}];    \
}

@interface GlobalUtil : NSObject

#pragma mark - Basic

/**
 * 判断对象是否为空
 *  object == nil || [object isEqual:[NSNull null]]
 */
+ (BOOL)isNull:(id)object;
+ (BOOL)isNotNull:(id)object;

/**
 * 判断array是否为空
 *  (array == nil || [array isEqual:[NSNull null]] || array.count <= 0)
 */
+ (BOOL)isEmptyArray:(NSArray *)array;

+ (NSURL *)urlFromString:(NSString *)string;

//Base64解码:
+ (NSString *)base64DecodeString:(NSString *)string;
//Base64编码:
+ (NSString *)base64EncodeString:(NSString *)string;

/**
 * 数组插入未重复的对象
 */
+ (void)distinctAddOject:(id)object intoArray:(NSMutableArray *)array;
/**z
 * 随机排序一个数组
 */
+ (NSArray *)randomArray:(NSArray *)array;

/*
 * 打印出数组中信息（array元素为NSNumber）
 */
+ (NSString *)debugArray:(NSArray *)array;
/*
 * 去掉数据中最值（array元素为NSNumber）
 */
+ (void)trimArray:(NSMutableArray *)array isMax:(BOOL)isMax;
/*
 * 去掉数据中最大值和最小值（array元素为NSNumber）
 */
+ (void)trimArrayMaxMin:(NSMutableArray *)array;

/**
 * 获取系统剩余内存 MB
 */
+ (double)availableMemory;

#pragma mark - Device

/**
 * 判断设备是否竖向放置
 */
+ (BOOL)isOrientationVertical;
+ (BOOL)isOrientationVertical:(UIInterfaceOrientation)orientation;

/**
 * 获取当前方向
 */
+ (UIInterfaceOrientation)currentOrientation;

/**
 * 判断设备是否iPad
 */
+ (BOOL)isDevicePad;

+ (NSString *)documentPath;

/**
 * 版本信息
 */
+ (NSString *)appVersion;
+ (NSString *)buildVersion;

/**
 * 获取设备Id
 */
+ (NSString *)deviceID __deprecated;

/**
 * 设置指定UIColor的Alpha值，返回新的UIColor
 */
+ (UIColor *)changeColor:(UIColor *)orginColor withAlpha:(float)newAlpha;

#pragma mark - View

/**
 * 从名称为viewClass的xib中，创建ViewController实例
 */
+ (id)loadVCFromClass:(Class)viewClass;

/**
 * 从名称为viewClass的xib中，创建控件类实例
 */
+ (id)loadViewFromClass:(Class)viewClass;

/**
 * 为View设定圆角
 */
+ (void)roundForView:(UIView *)view withRadius:(float)radius;

/**
 * 为View设定边框
 */
+ (void)borderForView:(UIView *)view withColor:(UIColor *)color withWidth:(float)width;


/**
 * 加入view，靠近左上角（注：仅支持AutoResizing，不支持AutoLayout）
 */
+ (void)addSubview:(UIView *)subview toParent:(UIView *)view marginLeft:(int)leftMargin marginTop:(int)topMargin __deprecated;
+ (void)addSubview:(UIView *)subview toParent:(UIView *)view marginLeft:(int)leftMargin marginBottom:(int)bottomMargin __deprecated;
+ (void)addSubview:(UIView *)subview toParent:(UIView *)view marginRight:(int)rightMargin marginTop:(int)topMargin __deprecated;
+ (void)addSubview:(UIView *)subview toParent:(UIView *)view marginRight:(int)rightMargin marginBottom:(int)bottomMargin __deprecated;
/**
 * 加入view，靠近上方，横向居中（注：仅支持AutoResizing，不支持AutoLayout）
 */
+ (void)addSubview:(UIView *)subview toParent:(UIView *)view marginTop:(int)topMargin __deprecated;
/**
 * 加入view，靠近下方，横向居中（注：仅支持AutoResizing，不支持AutoLayout）
 */
+ (void)addSubview:(UIView *)subview toParent:(UIView *)view marginBottom:(int)bottomMargin __deprecated;
/**
 * 加入view，横纵都居中（注：仅支持AutoResizing，不支持AutoLayout）
 */
+ (void)addSubview:(UIView *)subview toParent:(UIView *)view __deprecated;

/**
 * 计算文字实际占用的大小
 */
+ (CGSize)sizeFortext:(NSString *)text withFont:(UIFont *)font constrainedToSize:(CGSize)size;
+ (CGSize)sizeFortext:(NSString *)text withFont:(UIFont *)font constrainedToSize:(CGSize)size lineSpace:(CGFloat)lSpace wordSpace:(CGFloat)wSpace;
#pragma mark - Image

/**
 * 修改图片大小
 */
+ (UIImage *)scaleImage:(UIImage *)originImage toResolution:(CGSize)size;

/**
 * 等比例缩放图像
 */
+ (UIImage *)scaleImage:(UIImage *)originImage toLength:(int)length;
+ (UIImage *)shrinkImage:(UIImage *)originImage toLength:(int)length;

/**
 * 将彩色图片转化为灰白
 */
+ (UIImage *)grayImageForImage:(UIImage *)image;

/**
 * 根据指定颜色 创建1x1的图像
 */
+ (UIImage *)imageFromColor:(UIColor *)color;

/**
 * 图像模糊处理
 */
+ (UIImage *)blurImage:(UIImage *)originImage;

#pragma mark - JSON

//对象(字典) -> JSON串
+ (NSString *)jsonStringFromObject:(id)object;
//JSON串 -> 对象
+ (id)objectFromJsonString:(NSString *)jsonString;
//对象 -> 字典
+ (NSDictionary *)getObjectData:(id)obj;
//对象 -> JSON
+ (NSData *)getJSON:(id)obj options:(NSJSONWritingOptions)options error:(NSError**)error;
//数组 -> JSON
+ (id)getObjectInternal:(id)obj;
//打印对象中的字段
+ (void)print:(id)obj;

//将NSNumber、NSString 解析字符串：如果value为空，则返回@""
+ (NSString *)parseString:(id)value;
//将NSNumber、NSString 解析Int
+ (int)parseInt:(id)object;
//将NSNumber、NSString 解析NSInteger
+ (NSInteger)parseInteger:(id)object;
//将NSNumber、NSString 解析Long
+ (long)parseLong:(id)object;
//将NSNumber、NSString 解析LongLong
+ (long long)parseLongLong:(id)object;
//将NSNumber、NSString 解析Float
+ (float)parseFloat:(id)object;
//将NSNumber、NSString 解析Double
+ (double)parseDouble:(id)object;
//将NSNumber、NSString 解析BOOL
+ (BOOL)parseBool:(id)object;

#pragma mark - Date & Time

/**
 * 比较当天的时间是否处于 某点某分 到 某点某分 之间
 *  如： 11:00 在 7:00 - 15:00 之间，
        22:00 在 20:00 - 8:00 之间
 */
+ (BOOL)isTime:(NSDate *)time between:(NSDate *)startTime and:(NSDate *)endTime;

/**
 * 生成新的时间： date的日期(年、月、日) + time的时间（时、分、秒）
 */
+ (NSDate *)createDate:(NSDate *)date withTime:(NSDate *)time;
+ (NSInteger)createDateStamp:(NSInteger)dateStamp withTimeStamp:(NSInteger)timeStamp;


//kvc 获取所有key值
+ (NSArray *)getAllIvar:(id)object;
//获得所有属性
+ (NSArray *)getAllProperty:(id)object;

@end
